Title: SQL BT (By-BKK) / 11 Aggregates
Tags: Obsidian_to_Anki

Q: What clause is used to filter groups after aggregation in SQL?
A: HAVING

Q: True or False: HAVING is used only with GROUP BY, not with WHERE.
A: True

Q: How is HAVING different from WHERE in SQL queries?
A: WHERE filters rows before grouping, HAVING filters after grouping

Q: Write the SQL structure for using HAVING with GROUP BY.
A: SELECT group_by_column, AGG_FUNC(column) AS alias FROM mytable WHERE condition GROUP BY column HAVING group_condition

Q: When is HAVING especially useful in SQL?
A: When filtering grouped rows based on aggregate results

Q: Reverse card: HAVING
A: Which clause filters grouped results after aggregation in SQL?

Q: Reverse card: WHERE filters before grouping, HAVING after grouping
A: How do WHERE and HAVING clauses differ in SQL GROUP BY queries?

Q: Reverse card: True
A: Are you allowed to use HAVING only with GROUP BY in SQL?

Q: Write a query to find the number of Artists in the studio.
A: SELECT COUNT(*) FROM employees WHERE role = 'Artist'

Q: Write a query to find employee counts for each role.
A: SELECT role, COUNT(*) FROM employees GROUP BY role

Q: How do you find the total years worked by all Engineers?
A: SELECT SUM(years_employed) FROM employees WHERE role = 'Engineer'